/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cxhd.pacs;

import com.cxhd.pacs.tools.DateUtil;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Administrator
 */
public class DataConfig {

    private static DataConfig dataConfig;

    private long IDcount;
    private String IDDate;
    private String hospitalName;
    private String zjurl;
     private String smsurl;
    private List<String> pluginList = new ArrayList<String>();
    
     private Map<String, String> config = new HashMap<String, String>();

    private Map<String, String> mapHostIdCache = new HashMap<String, String>();

    public static DataConfig getInstance() {

        if (dataConfig == null) {

            dataConfig = new DataConfig();
        }
        return dataConfig;
    }

    public boolean checkPlugin(String pluginName) {
        return pluginList.contains(pluginName);
    }

    public void addMapHostIdCache(String key, String value) {
        mapHostIdCache.put(key, value);
    }

    public String getHostIdCache(String uuid) {
        return mapHostIdCache.get(uuid);
    }

    public long getIDcount() {
        return IDcount;
    }

    public void setIDcount(long IDcount) {
        this.IDcount = IDcount;
    }

    public String getIDDate() {
        return IDDate;
    }

    public void setIDDate(String count) {
        this.IDDate = DateUtil.getNum() + "@" + count;
        Db.update("replace into config set name='IDDate',value='" + IDDate + "'");
    }

    public void initConfig() {

        try {
            this.IDDate = Db.findFirst("select * from config where name='IDDate'").get("value");
            this.hospitalName = Db.findFirst("select * from config where name='hospitalName'").get("value");
            this.zjurl = Db.findFirst("select * from config where name='zjurl'").get("value");
             
            Record re = Db.findFirst("select * from config where name='pluginList'");
            if (re != null) {
                String pluginNames[] = re.getStr("value").split(",");
                for (String item : pluginNames) {
                    pluginList.add(item);
                }
            }
            this.smsurl = Db.findFirst("select * from config where name='smsurl'").get("value");

        } catch (Exception e) {
        }
         List<Record> list = Db.find("select * from config");
            Map<String, String> map = new HashMap<String, String>();
            if (!list.isEmpty()) {
                for (Record re : list) {
                    map.put(re.getStr("name"), re.getStr("value"));
                }
                this.setConfig(map);
            }
        
        
    }

    public String getHospitalName() {
        return hospitalName;
    }

    public void setHospitalName(String hospitalName) {
        this.hospitalName = hospitalName;
    }

    public String getZjurl() {
        return zjurl;
    }

    public void setZjurl(String zjurl) {
        this.zjurl = zjurl;
    }

    public String getSmsurl() {
        return smsurl;
    }

    public void setSmsurl(String smsurl) {
        this.smsurl = smsurl;
    }

    public Map<String, String> getConfig() {
        return config;
    }

    public void setConfig(Map<String, String> config) {
        this.config = config;
    }

}
